//
//  XZHHomeNoteDetailViewController.m
//  Piece
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "XZHHomeNoteDetailViewController.h"
#import "XZHHomeNoteTableViewCell.h"
#import "XZHHomeNoteModel.h"

@interface XZHHomeNoteDetailViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation XZHHomeNoteDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.86 green:0.87 blue:0.88 alpha:1.00];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(didClickedLeftBarButton:)];
    [self setUpHomeDetailTableView];
    // Do any additional setup after loading the view.
}

- (void)setUpHomeDetailTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 49 - 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"XZHHomeNoteTableViewCell" bundle:nil] forCellReuseIdentifier:@"noteTableViewCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
//        [tableView setContentOffset:CGPointMake(0, 0) animated:NO];
        XZHHomeNoteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"noteTableViewCell"];
        cell.detailModel = self.model;
//        NSData *_decodedImageData = [[NSData alloc] initWithBase64Encoding:self.model.image];
//        UIImage *_decodedImage = [UIImage imageWithData:_decodedImageData];
//        cell.coverImageView.image = _decodedImage;
//        cell.contentLabel.text = self.model.content;
//        cell.titlesLabel.text = @"From PIECE / Self";
//        cell.timeLabel.text = self.model.date;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        cell.backgroundColor = [UIColor clearColor];
        cell.userInteractionEnabled = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        XZHHomeNoteModel *model = self.model;
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName,nil];
        CGRect newRect = [model.content boundingRectWithSize:CGSizeMake(ScreenWidth - 36, 8000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        return 420 + newRect.size.height + 55;
    } else {
        return 250;
    }
    
}

- (void)didClickedLeftBarButton:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:NO];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
